import React from 'react';
import { Modal, Row, Col, Form, InputNumber, message } from 'antd';
const R = require('ramda');
const FormItem = Form.Item;

export default Form.create({ wrappedComponentRef: true })(class DrawerLimited extends React.Component {

	constructor(props) {
		super(props);
		this.state = { open: false }
	}

	handleCancel = () => {
		this.setState({ open: false })
		this.props.form.resetFields();
	}

	handleOpen = () => {
		this.setState({ open: true })
	}

	handleConfirm = (method) => {
		this.props.form.validateFields((errors, values) => {
			if (errors) return;
			let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource
			this.props.dispatch({
				type: 'drawer/updateDrawer',
				payload: {
					id: dataSource.id,
					...values,
					cstid: dataSource.cstid,
					onSuccess: () => {
						this.props.handleSearch();
						this.handleCancel();
					}

				}

			})


		})
	}

	render() {

		const { getFieldDecorator } = this.props.form;
		const formItemLayout = { labelCol: { xs: { span: 8 }, sm: { span: 10 } }, wrapperCol: { xs: { span: 15 }, sm: { span: 10 } } };
		let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
		return (
			<Modal maskClosable={false} visible={this.state.open} title={"开票人限额修改"} width={400} onCancel={this.handleCancel} onOk={this.handleConfirm}>
				<Form>
					<Row>
						<Col span={25}>
							<FormItem {...formItemLayout} label="每月限额(万USD)" hasFeedback>
								{getFieldDecorator('monthlylimit', {
									rules: [{
										required: true, message: '请输入每月限额(万USD)',
									}],
									initialValue: dataSource.monthlylimit
								})(
									<InputNumber style={{ width: '100%' }} />
									)}
							</FormItem>
						</Col>
					</Row>
					<Row>
						<Col span={25}>
							<FormItem {...formItemLayout} label="单笔限额(万USD)" hasFeedback>
								{getFieldDecorator('ticketlimit', {
									rules: [{
										required: true, message: '请输入单笔限额(万USD)',
									}],
									initialValue: dataSource.ticketlimit
								})(
									<InputNumber style={{ width: '100%' }} />
									)}
							</FormItem>
						</Col>
					</Row>
				</Form>
			</Modal>
		);
	}
})


// WEBPACK FOOTER //
// ./public/src/components/order/components/EditDrawer.js